<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%
    String visitId = input.getDesc("visit_id", "-1");
    List<Map> visits = QBuilder.db("basedb").select("new map(v.id as visit_id, v.name as patient_name, v.isconfirmed as confirm, v.surveyId as survey_id, s.title as title, v.score as score)").from("Visit as v, Survey as s").where(new Where("v.hospital=", hospital).and("v.status = ", STATUS_ENABLE).and("s.hospital=", hospital).and("v.category=3").and("s.category=3").and("v.id=", visitId).and("s.id = v.surveyId")).order("v.cTime", QBuilder.desc).query().getResultObj();
    if (isEmpty(visits)) {
        msg = new Message(30041, "暂未参与任何健康评测");
        msg.put("data", new ArrayList());
        Tools.encryptPrint(out, msg);
        return;
    }
    Map map = visits.get(0);
    int surveyId = Tools.getInt(map.get("survey_id") + "", -99999);
    List<SurveyScore> scores = QBuilder.db("basedb").queryHql("from SurveyScore where sid in =" + surveyId);
    int score = Tools.getInt(map.get("score") + "", 0);
    map.put("content", "");
    for (int j = 0; j < scores.size(); j++) {
        SurveyScore surveyScore = scores.get(j);
        if (surveyId == surveyScore.getSid() && score >= surveyScore.getMin() && score <= surveyScore.getMax()) {
            map.put("content", surveyScore.getContent());
            break;
        }
    }
    msg.put("data", map);
    Tools.encryptPrint(out, msg);
%>
